<template>
  <header>
    <div class="left">
      <img src="../../../assets/logo.png" alt="">
      <span style="margin-left: 76px">安全运行天数 <span style="font-family: 'bigfont';color: #7CDAFA; font-size: 36px; margin: 0 10px">{{ run }}</span> 天</span>
    </div>
    <div class="center">{{ this.$store.state.user.name }}</div>
    <div class="right">{{ realTime }}</div>
  </header>
</template>

<script>
export default {
  props: {
    run: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      time: null,
      realTime: ''
    }
  },
  mounted() {
    this.time = setTimeout(this.initTime, 1000)
  },
  methods: {
    initTime() {
      clearTimeout(this.time) // 清除定时器
      var dt = new Date()
      var y = dt.getFullYear()
      var mt = dt.getMonth() + 1
      mt = mt < 10 ? ('0' + mt) : mt
      var day = dt.getDate()
      day = day < 10 ? ('0' + day) : day
      var h = dt.getHours() // 获取时
      h = h < 10 ? ('0' + h) : h
      var m = dt.getMinutes() // 获取分
      m = m < 10 ? ('0' + m) : m
      var s = dt.getSeconds() // 获取秒
      s = s < 10 ? ('0' + s) : s
      this.realTime = y + '/' + mt + '/' + day + '              ' + h + ':' + m + ':' + s
      this.time = setTimeout(this.initTime, 1000) // 设定定时器，循环运行
    }
  }
}
</script>

<style lang="scss" scoped>
header {
    display: flex;
    justify-content: space-between;
    height: 78px;
    text-align: center;
    background:  url('../../../assets/header.png') no-repeat;
    background-size: 100% 100%;
    .left {
        position: relative;
        flex: 1;
        font-size: 22px;
        font-weight: 400;
        align-self: flex-end;
        text-align: left;
        text-indent: 51px;
        color: #fff;
        img {
            position: absolute;
            bottom: -20px;
        }
    }
    .center {
        width: 500px;
        // border: 1px solid #000;
        line-height: 80px;
        font-family: Adobe Heiti Std;
        font-weight: bold;
        color: #FFFFFF;
        text-shadow: 0px 5px 0px rgba(0, 113, 101, 0.5);
        font-size: 32px;
        letter-spacing: 5px;
    }
    .right {
        flex: 1;
        text-align: right;
        padding-right: 51px;
        font-size: 24px;
        font-family: 'bigfont';
        color: #7CDAFA;
        align-self: flex-end;
    }
}
</style>
